package com.cloudcc.mobile.view.activity;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.View.OnClickListener;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import butterknife.Bind;

import com.cloudcc.mobile.R;
import com.cloudcc.mobile.adapter.NewSelectAdapter;
import com.cloudcc.mobile.entity.beau.BeauInfoEntity;
import com.cloudcc.mobile.entity.beau.BeauInfoEntity.ObjMenu;
import com.cloudcc.mobile.manager.RunTimeManager;
import com.cloudcc.mobile.view.base.BaseActivity;
import com.google.gson.JsonObject;

//选择文件操作类
public class NewSelectActivity extends BaseActivity {
	@Bind(R.id.new_selece_btn)
	Button guanbibtn;
	@Bind(R.id.new_selece_listview)
	ListView mListview;
	NewSelectAdapter adapter;
	List<String> list = null;
	String mEntityId,mEntityNameID,jsonname;
	private BeauInfoEntity mBeauInfo;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
//		setFinishOnTouchOutside(true);
		addListener();
		addData();
	}

	private void addData() {
		list = new ArrayList<String>();
		list = (List<String>) getIntent().getSerializableExtra(
				"Leftlist");
		mEntityId = getIntent().getStringExtra("mEntityId");
		mEntityNameID = getIntent().getStringExtra("mEntityNameID");
		mBeauInfo = (BeauInfoEntity) getIntent().getSerializableExtra("mBeauInfo");
		jsonname = getIntent().getStringExtra("jsonname");
		adapter = new NewSelectAdapter(mContext,list,mEntityId,mEntityNameID,mBeauInfo,jsonname);
		mListview.setAdapter(adapter);
		ViewTreeObserver vto = mListview.getViewTreeObserver();     
        vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {   
            @Override     
            public void onGlobalLayout() {   
            	mListview.getViewTreeObserver().removeGlobalOnLayoutListener(this);  
            	if(mListview.getHeight()>1500){
            		mListview.setLayoutParams(  
        	                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1500));  
            	}
            	mListview.getWidth();  
            }     
        }); 
	}
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		RunTimeManager.getInstance().setIsrem(false);
		finish();
		return super.onTouchEvent(event);
	}
	private void addListener() {
		guanbibtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				RunTimeManager.getInstance().setIsrem(false);
				finish();
			}
		});
	
	}

	@Override
	public int getLayoutId() {
		return R.layout.new_select_add;
	}

}
